package org.example.service.impl;

import io.swagger.v3.oas.annotations.servers.Server;
import org.example.mapper.SuperAdminMapper;
import org.example.model.SuperAdmin;
import org.example.model.SuperAdminExample;
import org.example.service.SuperAdminService;
import org.example.vo.LoginResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SuperAdminServiceImpl implements SuperAdminService {

    @Autowired
    private SuperAdminMapper superAdminMapper;

    @Override
    public LoginResult login(String name, String pwd) {
        LoginResult loginResult = new LoginResult();
        SuperAdminExample superAdminExample = new SuperAdminExample();
        superAdminExample.createCriteria().andNameEqualTo(name);
        List<SuperAdmin> superAdmins =  superAdminMapper.selectByExample(superAdminExample);
        if (superAdmins.isEmpty()) {
            loginResult.setCode("nameError");
            loginResult.setMessage("用户不存在");
        }else if(superAdmins.size() == 1 && !superAdmins.get(0).getPwd().equals(pwd)){
            loginResult.setCode("pwdError");
            loginResult.setMessage("密码不正确");
        }else if(superAdmins.size() == 1 && superAdmins.get(0).getPwd().equals(pwd)){
            loginResult.setCode("success");
            loginResult.setMessage("登录成功");
        }
        return loginResult;
    }
}
